<template>
    <el-dialog v-model="dialogFormVisible" :title="title" @close="closeDialog" :z-index="1000">
        <el-form :model="addEvReviewForm" ref="addEvReviewRef" :rules="addEvReviewrules">

            <el-form-item label="评价类别" :label-width="formLabelWidth" prop="typeId">
                <el-select clearable v-model="addEvReviewForm.typeId" placeholder="请选择评价类别">
                    <el-option v-for=" item in typeList" :value="item.id" :label="item.name"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="评价标题" :label-width="formLabelWidth" prop="title">
                <el-input v-model="addEvReviewForm.title" autocomplete="off" ref="name" placeholder="请填写评价标题">
                </el-input>
            </el-form-item>
            <el-form-item label="评价说明" :label-width="formLabelWidth" prop="brief">
                <el-input v-model="addEvReviewForm.brief" autocomplete="off" ref="name" placeholder="请填写评价说明">
                </el-input>
            </el-form-item>
            <!-- <el-form-item label="内容" :label-width="formLabelWidth" prop="content">
                <el-input v-model="addEvReviewForm.content" autocomplete="off" ref="name" placeholder="请填写内容">
                </el-input>
            </el-form-item> -->
            <!-- <el-form-item label="发布时间" :label-width="formLabelWidth">
                <el-date-picker v-model="value1" type="datetimerange" start-placeholder="开始时间" end-placeholder="结束时间"
                    value-format="YYYY-MM-DD HH:mm:ss" />
            </el-form-item> -->
            <!-- <el-form-item label="开始时间" :label-width="formLabelWidth" prop="startTime" >
                <el-input v-model="addEvReviewForm.startTime" autocomplete="off" ref="name" placeholder="请填写开始时间">
                </el-input>
              

            </el-form-item>
            <el-form-item label="结束时间" :label-width="formLabelWidth" prop="endTime" >
                <el-input v-model="addEvReviewForm.endTime" autocomplete="off" ref="name" placeholder="请填写结束时间">
                </el-input> 
            </el-form-item>-->
           <el-form-item label="权重" :label-width="formLabelWidth" prop="sortNum" >
                <el-input v-model="addEvReviewForm.sortNum" type="number" autocomplete="off" ref="name" placeholder="请填写权重">
                </el-input>
            </el-form-item>
              <!--
            <el-form-item label="状态" :label-width="formLabelWidth" prop="status" v-if="addEvReviewForm.id">
                <el-input v-model="addEvReviewForm.status" autocomplete="off" ref="name" placeholder="请填写状态"></el-input>
            </el-form-item>
            <el-form-item label="创建时间" :label-width="formLabelWidth" prop="createTime" v-if="addEvReviewForm.id">
                <el-input v-model="addEvReviewForm.createTime" autocomplete="off" ref="name" placeholder="请填写创建时间">
                </el-input>
            </el-form-item>
            <el-form-item label="创建人" :label-width="formLabelWidth" prop="createNumber">
                <el-input v-model="addEvReviewForm.createNumber" autocomplete="off" ref="name" placeholder="请填写创建人">
                </el-input>
            </el-form-item>
            <el-form-item label="创建时间" :label-width="formLabelWidth" prop="createName">
                <el-input v-model="addEvReviewForm.createName" autocomplete="off" ref="name" placeholder="请填写创建时间">
                </el-input>
            </el-form-item> -->
        </el-form>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="cancel()">取消</el-button>
                <el-button type="primary" @click="save()">保存</el-button>
            </span>
        </template>
    </el-dialog>
</template>

<script>
import { ref } from "vue";
import { httpService } from "@/utils/httpService";
import { ElMessage, ElForm } from "element-plus";
import { vxRule } from "@/utils/validator";

export default {
    name: "AddEvReview",
    components: { ElForm, ElMessage },
    data() {
        return {
            dialogFormVisible: ref(false),
            formLabelWidth: "120px",
            title: "",
            personnelType: "",
            typeList: [],
            value1: "",
            addEvReviewForm: {
                title: "",
                typeId: "",
                brief: "",
                content: "",
                startTime: "",
                endTime: "",
                sortNum: "",
                status: "",
                createTime: "",
                createNumber: "",
                createName: "",
            },
            // 校验规则
            addEvReviewrules: {
                title: vxRule(true, null, "blur"),
                // brief: vxRule(true, null, "blur"),
                typeId: vxRule(true, null, "blur"),
                // content: vxRule(true, null, "blur"),
                // createNumber: vxRule(true, null, "blur"),
                // createName: vxRule(true, null, "blur"),
            },
        };
    },
    methods: {
        closeDialog() {
            this.clear();
        },
        cancel() {
            this.dialogFormVisible = false;
            this.clear();
        },
        getEvReviewById(id) {
            httpService("/javaApi/evReview/queryById", { id: id }, "get").then(
                (data) => {
                    this.addEvReviewForm = data;
                    const value1 = [
                        data.startTime,
                        data.endTime,
                    ]
                    this.value1 = value1;
                }
            );
        },
        getEvTypeList() {
            httpService(
                "/javaApi/evType/queryAll",
                {
                },
                "get"
            ).then((data) => {
                this.typeList = data;
            });
        },
        clear() {
            this.dialogFormVisible = false;
            //清空form
            this.addEvReviewForm.id = "";
            this.addEvReviewForm.title = "";
            this.addEvReviewForm.brief = "";
            this.addEvReviewForm.content = "";
            this.addEvReviewForm.startTime = "";
            this.addEvReviewForm.endTime = "";
            this.addEvReviewForm.sortNum = "";
            this.addEvReviewForm.status = "";
            this.addEvReviewForm.createTime = "";
            this.addEvReviewForm.createNumber = "";
            this.addEvReviewForm.createName = "";
            this.addEvReviewForm.typeId = "";
        },
        save() {
            this.$refs.addEvReviewRef.validate((valid) => {
                if (valid) {
                    let params = new FormData(); //创建一个form对象,必须是form对象否则后端接受不到数据
                    params.append("title", this.addEvReviewForm.title);
                    params.append("brief", this.addEvReviewForm.brief);
                    // params.append("content", this.addEvReviewForm.content);
                    // params.append("startTime", this.addEvReviewForm.startTime);
                    params.append("typeId", this.addEvReviewForm.typeId);
                    params.append("timeRange", this.value1);
                    params.append("sortNum", this.addEvReviewForm.sortNum);
                    // params.append("status", this.addEvReviewForm.status);
                    // params.append("createTime", this.addEvReviewForm.createTime);
                    // params.append("createNumber", this.addEvReviewForm.createNumber);
                    // params.append("createName", this.addEvReviewForm.createName);
                    if (this.addEvReviewForm.id) {
                        params.append("id", this.addEvReviewForm.id);
                        httpService("/javaApi/evReview/edit", params, "post").then(
                            (data) => {
                                if (data.code == 200) {
                                    ElMessage.success("修改成功");
                                    this.clear();
                                    //刷新父组件的数据
                                    this.$parent.getEvReviewList();
                                } else {
                                    ElMessage.error("修改失败");
                                }
                            }
                        );
                    } else {
                        httpService("/javaApi/evReview/add", params, "post").then(
                            (data) => {
                                if (data.code == 200) {
                                    ElMessage.success("添加成功");
                                    this.clear();
                                    //刷新父组件的数据
                                    this.$parent.getEvReviewList();
                                } else {
                                    ElMessage.error("添加失败");
                                }
                            }
                        );
                    }
                } else {
                    return false;
                }
            });
        },
    },
};
</script>
<style>
.el-select {
    width: 100%;
}
</style>